<?php

namespace App\Http\Requests\Admin\Panx\DeviceSpec;

use App\Http\Requests\ApiRequest;
use App\Models\Panx\DeviceSpec;

/**
 * @property string code
 * @property string eyelash_threshold
 * @property string eyelash_length
 * @property string pupil_size
 * @property string eyeshadow_bright
 * @property string beautifulness
 * @property string lip_feather
 * @property string whiteness
 */
class DeviceSpecStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'code' => 'required|string|unique:device_specs,code|max:'.self::MAX_STRING,
        ];

        $dev_spec_rules = $this->assembleDevSpecRules();

        return $rules + $dev_spec_rules;
    }

    public function attributes()
    {
        return [
            'code' => trans('admin.device_spec_code')
        ];
    }

    /**
     * @return array
     */
    public function assembleDevSpecRules()
    {
        $rules = [];
        foreach(DeviceSpec::DEVICE_SPEC_KEYS as $spec)
        {
            $rules[$spec['field_name']] = 'required|numeric|between:'.$spec['min_value'].','.$spec['max_value'];
        }

        return $rules;
    }
}
